package com.hpxx.ylzswl.activity;

import android.os.Bundle;
import android.support.v4.view.ViewPager;

import com.hpxx.ylzswl.R;
import com.hpxx.ylzswl.adapter.FragmentAdapter;
import com.hpxx.ylzswl.base.BaseActivity;
import com.hpxx.ylzswl.base.BaseFragment;
import com.hpxx.ylzswl.fragment.LeadingFragment;
import com.universal.frame.leading.ScrollerViewPager;
import com.universal.frame.leading.SpringIndicator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author RoreyDiu
 * @TitleName 引导页
 */
public class GuideActivity extends BaseActivity {

    private ScrollerViewPager viewPager;
    private SpringIndicator spIndicator;
    private static int BAIDU_READ_PHONE_STATE = 100;

    private List<BaseFragment> fragmentList = new ArrayList<BaseFragment>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        initView();
        setSwipeBackEnable(false);
        initSvPager();
    }

    @Override
    public void initView() {
        viewPager = (ScrollerViewPager) findViewById(R.id.view_pager);
        spIndicator = (SpringIndicator) findViewById(R.id.sp_indicator);
    }

    /**
     * 初始化引导页
     */
    private void initSvPager() {
        String[] strs = {"1", "2", "3"};
        initFragmentList();

        this.viewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), this, strs, this.fragmentList));
        this.viewPager.fixScrollSpeed();
        this.spIndicator.setViewPager(this.viewPager);

        this.spIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                fragmentList.get(position).onFragmentRefresh(position);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {

            }
        });
    }


    /**
     * 添加图片数据与Fragment
     */
    private void initFragmentList() {
        int[] imgs = {R.mipmap.guide_2
                , R.mipmap.guide_3
                , R.mipmap.guide_4
               };

        for (int resId : imgs) {
            fragmentList.add(LeadingFragment.newInstance(resId));
        }
    }

}
